<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>银行系统 - 贷款申请</title>
<style>
body {
    font-family: Arial, sans-serif;
    margin: 0;
    padding: 0;
}

.header {
    background-color: #333;
    color: white;
    padding: 20px;
    text-align: center;
}

.navbar {
    background-color: #444;
    overflow: hidden;
}

.navbar a {
    float: left;
    display: block;
    color: white;
    text-align: center;
    padding: 14px 16px;
    text-decoration: none;
}

.navbar a:hover {
    background-color: #555;
}

.content {
    padding: 20px;
    max-width: 800px;
    margin: 0 auto;
}

.loan-form {
    background-color: #f9f9f9;
    padding: 20px;
    border-radius: 5px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

.form-group {
    margin-bottom: 15px;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: bold;
}

.form-group input, .form-group textarea {
    width: 100%;
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    box-sizing: border-box;
}

.form-group textarea {
    height: 100px;
}

button {
    background-color: #4CAF50;
    color: white;
    padding: 10px 15px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

button:hover {
    background-color: #45a049;
}

.error-message {
    color: #F44336;
    margin: 10px 0;
    padding: 10px;
    background-color: #ffcccc;
    border-radius: 4px;
}

.success-message {
    color: #4CAF50;
    margin: 10px 0;
    padding: 10px;
    background-color: #ccffcc;
    border-radius: 4px;
}

/* 弹窗样式 */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background-color: #fff;
    padding: 20px;
    border-radius: 5px;
    width: 90%;
    max-width: 400px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
    text-align: center;
}

.modal h3 {
    color: #333;
    margin-top: 0;
}

.modal-buttons {
    margin-top: 20px;
    display: flex;
    justify-content: center;
    gap: 10px;
}

.modal-button {
    padding: 8px 15px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
}

.confirm-button {
    background-color: #4CAF50;
    color: white;
}

.confirm-button:hover {
    background-color: #45a049;
}

.cancel-button {
    background-color: #f44336;
    color: white;
}

.cancel-button:hover {
    background-color: #d32f2f;
}
</style>
</head>
<body>
    <div class="header">
        <h1>银行系统 - 贷款申请</h1>
        <p>欢迎您，<c:out value="${sessionScope.user.username}" /></p>
    </div>
    
    <div class="navbar">
        <a href="index.jsp">首页</a>
        <a href="loan">我的贷款</a>
        <a href="applyLoan" class="active">申请贷款</a>
        <a href="account">我的账户</a>
        <a href="logout">退出登录</a>
    </div>
    
    <div class="content">
        <h2>贷款申请</h2>
        
        <c:if test="${not empty error}">
            <div class="error-message">${error}</div>
        </c:if>
        
        <c:if test="${not empty success}">
            <div class="success-message">${success}</div>
        </c:if>
        
        <div class="loan-form">
        
            <form id="loanApplicationForm" action="applyLoan" method="post">
                <div class="form-group">
                    <label for="amount">贷款金额 (元)</label>
                    <input type="number" id="amount" name="amount" step="0.01" required>
                </div>
                
                <div class="form-group">
                    <label for="dueDate">贷款期限 (选择到期日期)</label>
                    <input type="date" id="dueDate" name="dueDate" required>
                </div>
                
                <div class="form-group">
                    <label for="purpose">贷款用途</label>
                    <textarea id="purpose" name="purpose" required></textarea>
                </div>
                
                <button type="button" id="submitButton">提交申请</button>
                <button type="button" onclick="history.back()">取消</button>
            </form>
        </div>
    </div>
    
    <!-- 提交确认弹窗 -->
    <div id="confirmModal" class="modal">
        <div class="modal-content">
            <h3>确认提交贷款申请</h3>
            <p>您确定要提交贷款申请吗？提交后将无法修改申请信息</p>
            <div class="modal-buttons">
                <button class="modal-button confirm-button" id="confirmSubmit">确认提交</button>
                <button class="modal-button cancel-button" id="cancelSubmit">取消</button>
            </div>
        </div>
    </div>

    <script>
        // 获取DOM元素
        var submitButton = document.getElementById('submitButton');
        var confirmModal = document.getElementById('confirmModal');
        var confirmSubmit = document.getElementById('confirmSubmit');
        var cancelSubmit = document.getElementById('cancelSubmit');
        var loanApplicationForm = document.getElementById('loanApplicationForm');
        
        // 显示确认弹窗
        submitButton.addEventListener('click', function() {
            confirmModal.style.display = 'flex';
        });
        
        // 确认提交贷款申请
        confirmSubmit.addEventListener('click', function() {
            // 隐藏弹窗
            confirmModal.style.display = 'none';
            // 提交表单
            loanApplicationForm.submit();
        });
        
        // 取消提交
        cancelSubmit.addEventListener('click', function() {
            confirmModal.style.display = 'none';
        });
        
        // 点击弹窗外部关闭弹窗
        window.addEventListener('click', function(event) {
            if (event.target === confirmModal) {
                confirmModal.style.display = 'none';
            }
        });
        
        // 表单验证增强
        loanApplicationForm.addEventListener('submit', function(e) {
            // 这里可以添加额外的表单验证逻辑
            // 如果验证失败，可以调用 e.preventDefault() 阻止提交
        });
    </script>
</body>
</html>